<HTML>
<HEAD>
    <TITLE>北京出租房</TITLE>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <link href="style/mycss.css" rel="stylesheet" type="text/css"/>
    <link href="style/text.css" rel="stylesheet" type="text/css"/>
    <link href="style/btn.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var user = JSON.parse(localStorage.getItem("user"));
            $("#uname").text(user.uname);

            $.ajax({
                url: "myHouse",
                type: "post",
                data: {
                    pid: user.pid
                },
                success: function (result) {
                    if (result.meta.status === 200) {
                        for (var i = 0; i < result.data.length; i++) {
                            show(result.data[i]);
                        }
                    } else alert(result.meta.msg)
                },
                dataType: "json"
            });
        })

        function show(house) {
            var body = document.getElementById("myHouse");
            var tr = document.createElement("tr");
            var td_title = document.createElement("td");
            var a_title = document.createElement("a");
            a_title.innerText = house.title;
            a_title.href = "javascript:void(0)";
            a_title.onclick = function () {
                detail(house.hid);
            };
            td_title.appendChild(a_title);
            tr.appendChild(td_title);

            var td_money = document.createElement("td");
            td_money.align = "center";
            td_money.style = "height:30px;";
            td_money.innerText = house.money + "元";
            tr.appendChild(td_money);

            var td_time = document.createElement("td");
            td_time.align = "center";
            td_time.style = "height:30px;";
            td_time.innerText = house.time;
            tr.appendChild(td_time);

            var td_delete = document.createElement("td");
            td_delete.align = "center";
            td_delete.style = "height:30px;";
            var a_delete = document.createElement("a");
            a_delete.innerText = "[删除]";
            a_delete.href = "javascript:void(0)";
            a_delete.onclick = function () {
                deleteHid(house.hid);
            };
            td_delete.appendChild(a_delete);
            tr.appendChild(td_delete);

            var td_update = document.createElement("td");
            td_update.align = "center";
            td_update.style = "height:30px;";
            var a_update = document.createElement("a");
            a_update.innerText = "[修改]";
            a_update.href = "javascript:void(0)";
            a_update.onclick = function () {
                updateHid(house.hid);
            };
            td_update.appendChild(a_update);
            tr.appendChild(td_update);
            body.appendChild(tr);
        }

        function detail(id) {
            localStorage.setItem("hid", id);
            location.href = "detail.html";
        }

        function deleteHid(id) {
            var flag = window.confirm("是否确认删除？");
            if (flag) {
                $.ajax({
                    url: "deleteHouse",
                    type: "delete",
                    data: {
                        hid: id
                    },
                    success: function (result) {
                        if (result.meta.status === 100) {
                            alert(result.meta.msg);
                        } else location.href = "my.html";
                    }
                });
            }
        }

        function updateHid(id) {
            localStorage.setItem("hid", id);
            location.href = "post_confirm.html";
        }
    </script>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>

<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="5"><img src="images/top.jpg" width="780" height="170"></td>
    </tr>
    <tr>
        <td colspan="5"><img src="images/middle1.jpg" width="780" height="47"></td>
    </tr>
    <tr>
        <td width="38" background="images/middle2.jpg">&nbsp;</td>
        <td width="172" valign="top">

            <table align="center">
                <tr>
                    <td width=''><font color='red'>当前用户：<span id="uname"></span></font>
                    </td>
                </tr>
                <tr>
                    <td width='150'><a href="my.html">管理我的租房信息</a></td>
                </tr>
                <tr>
                    <td width='100'><a href="post.html">发布租房信息</a></td>
                </tr>
                <tr>
                    <td width='100'><a href="login.html">返回首页</a></td>
                </tr>
                <tr>
                    <td width='100'><a href="index.html">[注销]</a></td>
                </tr>
            </table>
        </td>
        <td width="35" background="images/layout_24.gif">&nbsp;</td>
        <td width="495">
            <table>
                <tr>
                    <td width="3%">&nbsp;</td>
                    <td width="97%">


                        <table width='450' border='0'>
                            <tr>
                                <TD>标题</TD>
                                <TD width='100' align='center'>月租金</TD>
                                <TD width='110' align='center'>发布日期</TD>
                                <TD width='50'>&nbsp;</TD>
                                <TD width='50'>&nbsp;</TD>
                            </tr>
                            <tr>
                                <td colspan='5'>
                                    <hr/>
                                </td>
                            </tr>

                            <tbody id="myHouse">

                            </tbody>

                            <tr>
                                <td colspan='5'>
                                    <hr/>
                                </td>
                            </tr>
                        </table>


                    </td>
                </tr>
                <tr>
                    <td colspan="2"></td>
                </tr>
            </table>
        </td>
        <td width="40" background="images/middle4.jpg">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="5"><img src="images/bottom.jpg" width="780" height="82"></td>
    </tr>
</table>
<P align="center">教育 版权所有</P>
<br/>
</BODY>
</HTML>